#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
int T,n,a[N],b[N],c[N];
void dfs(int k)
{
    if(k<=0)
    {
        for(int i=2;i<=n;i++)
        {
            for(int j=i-1;j>=1;j--)
                if(b[i]==b[j])
            {
                if(a[i]==a[j])c[i]=max(c[i],a[i]);
                break;
            }
        }
    }
    else
    {
        b[k]=1;
        dfs(k-1);
        b[k]=0;
        dfs(k-1);
    }
    return;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i],c[i]=0;
        dfs(n);
        int sum=0;
        for(int i=1;i<=n;i++)sum+=c[i];
        cout<<sum<<endl;
    }
    return 0;
}
